<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>单词首字母大写</title>
    <script>
      function firstWordToUpper(char) {
        /*1，分隔（每个单词对应一个数组项），
         *2，遍历（将句子中的单词首字母变大写）,
         *3，拼接
         */
        var result = char
          .split(" ")
          .map((m) => m.charAt(0).toUpperCase() + m.substr(1))
          .join(" ");
        console.log(result);
      }
      firstWordToUpper("i love javascript very much"); //I Love Javascript Very Much
    </script>
  </head>
  <body></body>
</html>
